package com.cloud.test.ahs.cloud.provider;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
//@RequestMapping("/v1")
public class HystrixController {
	@Autowired
    private DiscoveryClient client;

	
//	@Autowired
//    private HystrixService service;
//	
    /**
     * 调用依赖的服务
     */
//    @RequestMapping("/call")
//    public String callDependencyService(int id){
//        return service.callDependencyService();
//    }
    int i = 0;
    @RequestMapping(value = "/add" ,method = RequestMethod.GET)
    public Integer add(@RequestParam Integer a, @RequestParam Integer b) {
        ServiceInstance instance = client.getLocalServiceInstance();
        i++;
        Integer r = a + b +i;
        //logger.info("/add, host:" + instance.getHost() + ", service_id:" + instance.getServiceId() + ", result:" + r);
        System.out.println("客户端调用host:" + instance.getHost() + ", service_id:" + instance.getServiceId() );
        return r;
    }
    
	
}
